<?
include ".setup.php";

class lego_home extends lego_abstract{
	public $tabs;
	public function getDir(){ return dirname(__FILE__); }
	public function init(){
		CTitle::addSection("PHPLego");
		$this->tabs = new view_radio("tabs", $this->getName());
		$this->tabs->addItem("index", "Mysql");
        Output::assign('last_command', $this->_sess('last_command'));
	}
	
	function action_index(){
		$lego = new lego_mysql();
        $lego->run();
        Output::setContent($lego->getOutput());
        return Output::fetch("body_base.tpl");
	}
    
    function action_command(){
        $command = $this->_get("command");
        $this->_sessSet('last_command', $command);
        $lines = explode("\n", $command);
        $head = array_shift($lines);
        $body = join("\n", $lines);
        $head = trim($head);
        switch($head){
            case 'sql':
                $this->_goto("?lego_mysql=sql&sql=".urlencode($body));
        }
    }
}

$m = new lego_home;
$m->run();
echo $m->getOutput();
?>